package com.swyc.osschat.Test.localDateTime;

import java.time.*;

/**
 *
 * LocalDateTime now = LocalDateTime.now();
 * System.out.println("计算两个时间的差：");
 * LocalDateTime end = LocalDateTime.now();
 * Duration duration = Duration.between(now,end);
 * long days = duration.toDays(); //相差的天数
 * long hours = duration.toHours();//相差的小时数
 * long minutes = duration.toMinutes();//相差的分钟数
 * long millis = duration.toMillis();//相差毫秒数
 * long nanos = duration.toNanos();//相差的纳秒数
 * System.out.println(now);
 * System.out.println(end);
 * System.out.println("发送短信耗时【 "+days+"天："+hours+" 小时："+minutes+" 分钟："+millis+" 毫秒："+nanos+" 纳秒】");
 *
 *
 * LocalDateTime计算时间
 * 会费到期日 = 当前日期+卡延期天数+会费有效期
 * 当前日期：
 * java.time.LocalDateTime date = LocalDateTime.now();
 * 卡延期天数：7天
 * 会费有效期：5个月
 * 会费到期日 = date.plusDays(7).plusMonths(4))
 *
 * @Author: z156940l@outlook.com
 * @Date: 2021/2/20 14:27
 */
public class Java8Tester {

    public static void main(String args[]){
        Java8Tester java8tester = new Java8Tester();
        java8tester.testLocalDateTime();

        java8tester.testZonedDateTime();
    }

    public void testLocalDateTime(){

        // 获取当前的日期时间
        LocalDateTime currentTime = LocalDateTime.now();
        System.out.println("当前时间: " + currentTime);

        LocalDate date1 = currentTime.toLocalDate();
        System.out.println("date1: " + date1);

        Month month = currentTime.getMonth();
        int day = currentTime.getDayOfMonth();
        int seconds = currentTime.getSecond();

        System.out.println("月: " + month +", 日: " + day +", 秒: " + seconds);

        LocalDateTime date2 = currentTime.withDayOfMonth(10).withYear(2012);
        System.out.println("date2: " + date2);

        // 12 december 2014
        LocalDate date3 = LocalDate.of(2014, Month.DECEMBER, 12);
        System.out.println("date3: " + date3);

        // 22 小时 15 分钟
        LocalTime date4 = LocalTime.of(22, 15);
        System.out.println("date4: " + date4);

        // 解析字符串
        LocalTime date5 = LocalTime.parse("20:15:30");
        System.out.println("date5: " + date5);
    }

    public void testZonedDateTime(){

        // 获取当前时间日期
        ZonedDateTime date1 = ZonedDateTime.parse("2015-12-03T10:15:30+05:30[Asia/Shanghai]");
        System.out.println("date1: " + date1);

        ZoneId id = ZoneId.of("Europe/Paris");
        System.out.println("ZoneId: " + id);

        ZoneId currentZone = ZoneId.systemDefault();
        System.out.println("当期时区: " + currentZone);
    }
}
